<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<fieldset><legend>อาหารที่ไม่เหมาะสมกับโรค</legend>
        <form action="action.php" method="post">
<table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
  <tr>
    <th bgcolor="#d1e9ab" class="fieldname"><span class="spanfieldname">อาหาร</span></th>
    <th bgcolor="#d1e9ab" class="fieldname"><span class="spanfieldname">ความเหมาะสม</span></th>
    <th bgcolor="#d1e9ab" class="fieldname"><span class="spanfieldname">รายละเอียด</span></th>
    <th bgcolor="#d1e9ab" class="fieldname"><span class="spanfieldname">ลบ</span></th>
  </tr>
<?
require_once('../config.ini.php');
$diseaseid = $_GET['diseaseid'];
$sql = "SELECT food.foodid, food.foodname FROM food where food.status = '1'";
$result = mysql_query($sql);
$ckradio = "checked='checked'";
while ($row = mysql_fetch_array($result)) {
$sql1 = "SELECT diseasefood.diseaseid, diseasefood.foodid, diseasefood.foodtype, diseasefood.description FROM diseasefood WHERE diseasefood.diseaseid = '$diseaseid' and diseasefood.foodid = '$row[0]'";
$result1 = mysql_query($sql1);
$row1 = mysql_fetch_array($result1);
if ($row['0'] == $row1['1']) { $ck = 'checked="checked"'; $disradio = "disabled=''";} else { $ck = ''; $disradio = "disabled='disabled'";}
?>
  <tr>
    <td class="fieldname"><span class="spanfieldname"><? echo $row['1']; ?></span></td>
    <td class="fieldname"><span class="spanfieldname">
        <input type="radio" name="rdfood_<? echo $row['0']; ?>" id="rdfood_<? echo $row['0']; ?>"  value="1"  <? if($row1['2'] == "1") { echo $ckradio; } ?>/><label>เหมาะสม</label>
        <input type="radio" name="rdfood_<? echo $row['0']; ?>" id="rdfood_<? echo $row['0']; ?>"  value="0" <? if($row1['2'] == "0") { echo $ckradio; } ?>/><label>ไม่เหมาะสม</label>
    </span></td>
    <td class="fieldname"><span class="spanfieldname">
    <textarea name="rddis_<? echo $row['0']; ?>" id="rddis_<? echo $row['0']; ?>"><? echo $row1['3']; ?></textarea>
    </span></td>
    <td class="fieldname"><span class="spanfieldname"><img id="del_<? echo $row['0']; ?>" width="18px;" height="18px;" src="../images/delete-48.png" style="cursor:pointer" /></span></td>
  </tr>
<?
}
mysql_free_result($result);
mysql_close($link);
?>
</table>
<input type="hidden" name="diseaseid" id="diseaseid" value="<? echo $diseaseid; ?>" />
<input type="hidden" name="action" id="action" value="savediseasefood" />
<p><input type="submit" value="บันทึกข้อมูล" /></p>
</form>
</fieldset>
<script>
$(function() {
	$("img[id^='del_']").click(function() {
		var selectid = $(this).attr("id");
		var strselect = selectid.split("_");
		var selector = "input[name='rdfood_"+strselect[1]+"']";
		//var selector2 = "textarea[name='rddis_"+strselect[1]+"']"; //$("textarea[id^='rddis']")
		$(selector).attr("checked","");
		$(this).parent().parent().prev().find("textarea").val("");
		//$(selector2).attr("disabled","disable");
	});
});
</script>
</body>
</html>
